import { EMAIL_REGEX } from '../constants/regex';
import Web3Manager from './web3-manager';
import { isAddress } from '@ethersproject/address';

export const isEmailInvalid = (email: string) => {
    if (!email) {
        return false;
    }
    return !email.match(EMAIL_REGEX);
};

export const isAmountInvalid = (amount: number, maxAmount?: number, minAmount?: number) => {
    return Number.isNaN(amount) || amount < 0 || amount > maxAmount || amount < minAmount;
};

export const isWalletAddressInvalid = (walletAddress: string) => {
    const transformedAddress = walletAddress.replace('ronin:', '0x');
    return !isAddress(transformedAddress);
};

export const isOwnWallet = async (walletAddress: string) => {
    const currentWallet = await Web3Manager.getWalletAddress();
    return walletAddress.toLocaleLowerCase() === currentWallet.toLocaleLowerCase();
};

export const isTransactionHashInvalid = (hash: string) => {
    return !/^0x([A-Fa-f0-9]{64})$/.test(hash);
};
